package com.biz.primus.ms.stock.component.aspectj;

import com.biz.primus.model.stock.vo.IncrDepotStockReqVo;
import com.biz.primus.ms.stock.service.StockChangeLogService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * StockChangeAspect
 *
 * @author JKLiues
 * @date 2017年10月21日
 */
@Aspect
@Component
@Slf4j
public class StockChangeAspect {
    @Autowired
    private StockChangeLogService stockChangeLogService;


    @Pointcut(value = "@annotation(com.biz.primus.ms.stock.component.annotation.StockChangMark)")
    public void changeStock() {

    }

    @After(value = "com.biz.primus.ms.stock.component.aspectj.StockChangeAspect.changeStock()")
    public void logStockChange(JoinPoint jp) {
        Object[] args = jp.getArgs();
        try {
            IncrDepotStockReqVo reqVo = (IncrDepotStockReqVo) args[0];
            stockChangeLogService.saveLog(reqVo);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("库存更新记录异常{}", e.getMessage());
        }
    }
}